# 执行转换
import json

from api.service.rule_transfer_service import transform_rule_to_workflow


def test_transfer_rule():
    # 原始输入数据
    input_data = {
        "rule_code": "RULE_123456",
        "description": "上车总成类规则校验",
        "priority": 10,
        "active": True,
        "attrType": "基础属性",
        "attrClassify": "属性分类树节点",
        "conditions_group": {
            "logical_operator": "and",
            "conditions": [
                {
                    "operator": "contains",
                    "field": "field_name",
                    "value": "ab",
                    "sub_conditions": {
                        "logical_operator": "and",
                        "conditions": [
                            {
                                "operator": "contains",
                                "field": "field_name",
                                "value": ["ab", "cd"]
                            }
                        ]
                    }
                },
                {
                    "operator": "not contains",
                    "field": "field_name",
                    "value": "ab"
                }
            ]
        },
        "results": {
            "logical_operator": "and",
            "conditions": [
                {
                    "operator": "contains",
                    "field": "field_name",
                    "value": "ab",
                    "sub_conditions": {
                        "logical_operator": "and",
                        "conditions": [
                            {
                                "operator": "contains",
                                "field": "field_name",
                                "value": ["ab", "cd"]
                            }
                        ]
                    }
                },
                {
                    "operator": "not contains",
                    "field": "field_name",
                    "value": "ab"
                }
            ]
        },
        "error_code": "E101",
        "error_message": "当物料大类为8001或8002，且名称为上车总成类时，必须设置物料组为40101..."
    }
    result = transform_rule_to_workflow(input_data)
    print(json.dumps(result, indent=4, ensure_ascii=False))
